<?php
/* 收藏类
 * @author  zhanghui
 * @create_date 2008-02-28
 */
class Favourite{
	function __construct(){}
	function __destruct(){}
	
	/**
     * 加入收藏
     * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,folderid,postid,url,title,tag,content,read_open_type,favourite_date
     */
	function addFavourite($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_favourite";
		$str_query .= " set";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= ",folderid={$arr_input['folderid']}";
		$str_query .= ",url='{$arr_input['url']}'";
		$str_query .= ",title='{$arr_input['title']}'";
		$str_query .= ",tag='{$arr_input['tag']}'";
		$str_query .= ",content='{$arr_input['content']}'";
		//$str_query .= ",read_open_type={$arr_input['read_open_type']}";
		$str_query .= ",favourite_date='".$conn->getCurrentTime()."'";
		
		$conn->executeQuery($str_query);
	}
	
	/**
     * 删除收藏
     * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,folderid,postid,url,title,tag,content,read_open_type,favourite_date
     */
	function deleteFavourite($conn,$arr_input){
		$str_query = "delete from";
		$str_query .= " baby_favourite";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= " and folderid={$arr_input['folderid']}";
		
		if(isset($arr_input['postid'])){
			$str_query .= " and postid={$arr_input['postid']}";
		}
		
		$conn->executeQuery($str_query);
	}
	
	/**
     * 编辑收藏
     * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,folderid,postid,url,title,tag,content,read_open_type,favourite_date
     */
	function editFavourite($conn,$arr_input){
		$str_query = "update";
		$str_query .= " baby_favourite";
		$str_query .= " set";
		$str_query .= " url='{$arr_input['url']}'";
		$str_query .= ",title='{$arr_input['title']}'";
		$str_query .= ",tag='{$arr_input['tag']}'";
		$str_query .= ",content='{$arr_input['content']}'";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= " and folderid={$arr_input['folderid']}";
		$str_query .= " and postid={$arr_input['postid']}";

		$conn->executeQuery($str_query);
	}
	
	/**
     * 获取收藏
     * @param $conn 数据库连接类
     * @param : array $arr_input - baby_id,folderid,postid,url,title,tag,content,read_open_type,favourite_date
     */
	function getFavouriteList($conn,$arr_input){
		$str_query = "select";
		if(isset($arr_input['cnt'])){
			$arr_input .= " count(1)";
		}else{
			$str_query .= " baby_id";
		    $str_query .= ",folderid";
		    $str_query .= ",postid";
		    $str_query .= ",url";
		    $str_query .= ",title";
		    $str_query .= ",tag";
		    $str_query .= ",content";
		    //$str_query .= ",read_open_type";
		    $str_query .= ",favourite_date";
		}
		$str_query .= " from";
		$str_query .= " baby_favourite";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= " and folderid={$arr_input['folderid']}";
		if(isset($arr_input['postid'])){
			$str_query = " and postid={$arr_input['postid']}";
		}
		
		$arr_output = $conn->selectQuery($str_query);
        return $arr_output;
	}
	           
}
?>